<?php get_header(); ?>
<!--end header-->
<div class="span-16" id="main-content">

    <h3 class="label-title">Tin tức</h3>
    <div class="span16" id="news">
        <?php
        /*
         * Query the latest post
         */
        global $post;
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
            'posts_per_page'=>'1',
            'post_type'=>'tintuc',
            'paged'=>$paged
        );
        $latest = new WP_Query($args);
        if($latest->have_posts()) : while($latest->have_posts()) : $latest->the_post(); ?>

        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <?php include ('post-meta.php'); ?>
            <?php the_excerpt(); ?>
        <?php endwhile; else: echo "Chưa có tin nào được đăng!"; endif; ?>
        <?php wp_reset_query(); ?>

        <div class="related-post">
            <h3>Các tin cũ hơn:</h3>
            <ul class="list">
            <?php
            /*
             * Query older title of post
                 */
            global $post;
            $args = array(
                'posts_per_page'=>'3',
                'offset'=>'1',
                'post_type'=>'tintuc'
            );
            $oder = new WP_Query($args);
            if($oder->have_posts()) : while($oder->have_posts()) : $oder->the_post(); ?>
                <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                <?php endwhile; else: echo "Chưa có tin cũ!"; endif; ?>
                <?php wp_reset_query(); ?>
            </ul>
        </div>
    </div><!--end news-->

    <h3 class="label-title">Nhà trọ</h3>
    <?php
    /*
     *     Query Nhà Trọ infomation - display numbers of latest Nhà Trọ
     */


      if(have_posts()) : while(have_posts()) : the_post(); ?>
      <?php
      /*
       * Get inportant infomation
       */
          $the_id = get_the_id();
          $diachi = get_post_meta($the_id,'_diachi',true);
          //$dientich = get_post_meta($the_id,'_dientich',true);
          $gioitinh = get_post_meta($the_id,'_gioitinh',true);
          $ghichu = get_post_meta($the_id,'_ghichu',false);
          $phongtrong = get_post_meta($the_id,'_phongtrong',true);
          /*
           * Price Infomation
           */
          $giaphong = get_post_meta($the_id,'_giaphong',true);
          $giadien = get_post_meta($the_id,'_giadien',true);
          //$gianuoc = get_post_meta($the_id,'_gianuoc',false);
          //$chiphikhac = get_post_meta($the_id,'_chiphikhac',false);

          /*
           * noi quy
           */
          //$noiquy = get_post_meta($the_id,'_noiquy',true);

          if(strcmp($gioitinh,'nam') == 0) $gioitinh = 'Nam';
          elseif(strcmp($gioitinh,'nu') == 0) $gioitinh = 'Nữ';
          else $gioitinh = "Nam & Nữ";

      ?>

    <div class="span-16 item">
        <div class="span-16">
            <div class="title span-11">
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            </div>
            <div class="price span-5 last">
                <h3 class="price"><?php echo $giaphong; ?> / tháng</h3>
            </div>
        </div>

        <?php include('post-meta.php'); ?>
        <div class="span-4 thumbnail">
            <?php
            /*
            * Display thumbnail
            */
            if ( has_post_thumbnail() )
                the_post_thumbnail( 'thumbnail' );
            else echo 'Hình chưa được tải lên';
            ?>
        </div>
        <div class="span-12 last">
            <ul class="properties list">
                <li class="location"><span>Địa điểm: </span><?php echo $diachi; ?></li>
                <li class="empty-room"><span>Số phòng trống hiện tại: </span><?php echo $phongtrong; ?></li>
                <li class="location"><span>Phòng dùng cho: </span><?php echo $gioitinh; ?></li>
                <?php if(!empty($ghichu) && strcmp(trim($ghichu[0][0]),'') != 0) { ?>
                <li class="item-note"><span>Ghi chú:</span>
                    <ul class="notes">
                        <?php foreach($ghichu[0] as $value) {
                            echo "<li>$value</li>";
                        }?>
                    </ul>
                </li>
                <?php } ;?>
            </ul><!--end list properties-->
            <p><a href="<?php the_permalink(); ?>" class="item-readmore">Xem chi tiết</a></p>
        </div>
    </div><!--end item-->

    <?php endwhile; else: echo "Chưa có nhà trọ được đăng!"; endif; ?>
    <?php wp_reset_query(); ?>

    <!--include bottom pagination-->
    <?php include ('bot-nav.php'); ?>

</div><!--end main-content-->
<!--begin sidebar-->
<?php get_sidebar(); ?>
<!--end sidebar-->
<!--begin footer-->
<?php get_footer(); ?>
<!--end footer-->